#include <stdio.h>
#include<stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t id = fork();

    if(id == 0)
    {
        int cnt = 10;
        printf("I'm child, pid = %d\n", getpid());

        while(cnt--)
        {
            sleep(1);
            printf("%d\n", cnt);
        }

        return 0;
    }

    int status = 0;
    pid_t ret = wait(&status);

    printf("wait over! status = %d, ret = %d\n", status, ret);

    if(WIFEXITED(status))
    {
        printf("子进程正常退出\n");
        printf("sig number = %d ",status & 0x7F);
        printf("exit code = %d\n", WEXITSTATUS(status));
    }
    else
    {
        printf("子进程异常退出\n");
        printf("sig number = %d ",status & 0x7F);
        printf("exit code = %d\n", WEXITSTATUS(status));
    }

    return 5;
}
